#include "Ball.h"
#include "SDL_opengl.h"
#include "Vector2.h"

#include <cmath>

Ball::Ball(float r): position(Vector2::ZERO), radius(r), mass(5), velocity(Vector2::ZERO) {}

bool Ball::testCollision(const Ball& ball)
{
	if ( (position - ball.position).getMagnitude() < (radius + ball.radius ) )
		return true;
	
	return false;
}

void Ball::update(const Ball& ball)
{
	position.x += velocity.x;
	if (testCollision(ball))
		position.x -= velocity.x;
	
	position.y += velocity.y;
	if (testCollision(ball))
		position.y -= velocity.y;
}

void Ball::draw()
{
	glBegin(GL_TRIANGLE_FAN);
	glVertex2f(position.x, position.y);
	for (int a = 0; a < 360; a += 5)
	{
		//glVertex2f(position.x + sin(a) * radius, position.y + cos(a) * radius);
	}
	glEnd();
}